package org.zerg.controller.web;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zerg.dto.Page;
import org.zerg.entity.Address;
import org.zerg.entity.Order;
import org.zerg.entity.User;
import org.zerg.service.UserService;

@Controller
@RequestMapping("user")
public class UserWebController {

	@Autowired
	private UserService userService;
	
	@Autowired
	private HttpSession session;
	
	@RequestMapping("/list")
	public String getUser(@RequestParam("page")int page){
		List<User> list = userService.getUser(page);
		Page pa = userService.pageMessage(page);
		session.setAttribute("list", list);
		session.setAttribute("page", pa);
		return "/user";
	}
	
	@ResponseBody
	@RequestMapping("/getaddress")
	public Address getAddressById(@RequestParam("id")int id){
		Address address = userService.getAddress(id);
		return address;
	}
	
	@RequestMapping("/getorder")
	public String getOrderById(@RequestParam("id")int id,@RequestParam("page")int page){
		List<Order> list = userService.getOrder(id,page);
		Page pa = userService.pageMessageForOr(page,id);
		session.setAttribute("list", list);
		session.setAttribute("page", pa);
		return "/myorder";
	}
	
}
